Surml Core
An embedded ONNX runtime directly in the Rust binary when compiling result in no need for installing ONNX runtime separately or worrying about version clashes with other runtimes.
This crate is just the Rust implementation of the Surml API. It is advised that you just use this crate directly if you are running a Rust server. It must be noted that the version of ONNX needs to be the same as the client when using this crate. For this current version of Surml, the ONNX version is 1.16.0
.
Compilation config
If nothing is configured the crate will compile the ONNX runtime into the binary. This is the default behaviour. However, if you want to use an ONNX runtime that is installed on your system, you can set the environment variable ONNXRUNTIME_LIB_PATH
before you compile the crate. This will make the crate use the ONNX runtime that is installed on your system.
This houses reusable errors that are used across all the crates in the Surml ecosystem, and these errors can construct HTTP responses for the Axum and Actix web frameworks.
Nix Support
At this point in time NIX is not directly supported. The ONNXRUNTIME_LIB_PATH
needs to be defined. This is explained in the Compilation config
section.
Usage
Surml can be used to store, load, and execute ONNX models.
Storing and accessing models
We can store models and meta data around the models with the following code:
use File;
use ;
use SurMlFile;
use Header;
use ;
// load your own model here (surrealml python package can be used to convert PyTorch,
// and Sklearn models to ONNX or package them as surml files)
let mut file = open.unwrap;
let mut model_bytes = Vec new;
file.read_to_end.unwrap;
// create a header for the model
let mut header = fresh;
header.add_column;
header.add_column;
header.add_output;
// add normalisers if needed
header.add_normaliser;
header.add_normaliser;
// create a surml file
let surml_file = new;
// read and write surml files
surml_file.write.unwrap;
let new_file = from_file.unwrap;
let file_from_bytes = from_bytes.unwrap;
Executing models
We you load a surml
file, you can execute the model with the following code:
use SurMlFile;
use ModelComputation;
use ArrayD;
use HashMap;
let mut file = from_file.unwrap;
let compute_unit = ModelComputation ;
// automatically map inputs and apply normalisers to the compute if this data was put in the header
let mut input_values = new;
input_values.insert;
input_values.insert;
let output = compute_unit.buffered_compute.unwrap;
// feed a raw ndarray into the model if no header was provided or if you want to bypass the header
let x = vec!;
let data: = arr1.into_dyn;
// None input can be a tuple of dimensions of the input data
let output = compute_unit.raw_compute.unwrap;
ONNX runtime assets
We can find the ONNX assets with the following link:
https://github.com/microsoft/onnxruntime/releases/tag/v1.16.2